export const localStorageConstant = {
    connectionKey : "connection"
}
import { getDB } from "@/js/localDB.js";
const db = getDB()
/**
 * 存储连接
 * @param connectionName
 * @param object
 */
export function storeConnection(connectionName,object) {



    db.open()
    //写入一些数据
    db.connectionTable.put(object).then (function(){
        //当数据存储完成后 我们可以读取它
        return db.connectionTable.get(object.connectionName);
    }).then(function (data) {
        console.log("data:" + data);
    }).catch(function(error) {
        //最后别忘了抓住任何可能发生在上面的代码块。
        console.log("error: " + error);
    }).finally(  ()=> {
        db.close()
    });

    // var map = localStorage.getItem(localStorageConstant.connectionKey)
    // map.set(connectionName,object)
}

export function getConnectionMap() {
    return localStorage.getItem(localStorageConstant.connectionKey)
}

/**
 * 判断连接是否存在
 * @param connectionName
 * @returns {boolean}
 */
export function isExistsConnection(connectionName) {
    console.log(localStorage)
    console.log(localStorage.getItem(localStorageConstant.connectionKey))
    var map = localStorage.getItem(localStorageConstant.connectionKey)
    console.log(map)
    console.log("---------------")
    for (let key of map.keys()) {
        console.log(key);
    }
    // if(localStorage.getItem(localStorageConstant.connectionKey).get(connectionName) == null){
    //     return true
    // }
    return false
}
